package org.jeecg.modules.demo.hydrology.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.modules.demo.hydrology.dto.PslcddyDto;
import org.jeecg.modules.demo.hydrology.entity.Pslcddy;
import org.jeecg.modules.demo.hydrology.mapper.PslcddyMapper;
import org.jeecg.modules.demo.hydrology.service.IPslcddyService;
import org.jeecg.modules.system.entity.SysDepart;
import org.jeecg.modules.system.mapper.SysDepartMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description: 排水量基础信息
 * @Author: jeecg-boot
 * @Date:   2024-04-17
 * @Version: V1.0
 */
@Service
public class PslcddyServiceImpl extends ServiceImpl<PslcddyMapper, Pslcddy> implements IPslcddyService {
    @Autowired
    private PslcddyMapper pslcddyMapper;
    @Autowired
    private SysDepartMapper sysDepartMapper;
    /**
     * 排水量基础信息-分页列表查询
     * @param page
     * @param queryWrapper
     * @return
     */
    @Override
    public IPage<PslcddyDto> getList(Page<Pslcddy> page, QueryWrapper<Pslcddy> queryWrapper) {
        Page<Pslcddy> pslcddyPage = pslcddyMapper.selectPage(page, queryWrapper);
        List<PslcddyDto> collect = pslcddyPage.getRecords().stream().map(pslcddy -> {
            PslcddyDto pslcddyDto = new PslcddyDto();
            BeanUtils.copyProperties(pslcddy, pslcddyDto);
            QueryWrapper<SysDepart> sysDepartQueryWrapper = new QueryWrapper<>();
            sysDepartQueryWrapper.eq("org_code", pslcddy.getStationMine());
            SysDepart sysDepart = sysDepartMapper.selectOne(sysDepartQueryWrapper);
            if (sysDepart != null){
                pslcddyDto.setStationName(sysDepart.getDepartName());
            }
            return pslcddyDto;
        }).collect(Collectors.toList());
        IPage<PslcddyDto> pslcddyDtoIPage = new Page<>();
        pslcddyDtoIPage.setRecords(collect);
        pslcddyDtoIPage.setTotal(pslcddyPage.getTotal());
        pslcddyDtoIPage.setPages(page.getPages());
        pslcddyDtoIPage.setSize(page.getSize());
        return pslcddyDtoIPage;
    }
}
